<?php

namespace App\Http\Controllers\Wechat;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use  App\Models\WxUser;
use  App\Libraries\classs\PhpRedis;
use EasyWeChat\Foundation\Application;
use  App\Models\User\Logs as UserLogs;

class BaseController extends Controller
{

     public $_uid;
     public $_user;
     public $_page_count = 10;
     public function __construct(){
         $user = session('wechat.oauth_user'); // 拿到授权用户资料
         $user_date = $user->original;
         $this->_user=PhpRedis::getInstance()->getRedisUser($user_date);
         view()->share('user',$this->_user);
         $app = new Application(config('wechat'));  //分享
         $js = $app->js;
         view()->share('js',$js);



         $this->_uid=$this->_user->id;
     }


     public function today(){
         $userlogs = UserLogs::where('created_at','>=',date('Y-m-d'))->where('x_uid','=',$this->_uid)->first();
         if(!$userlogs){
              $data=array(
                    'x_uid'=>$this->_uid,
                    'addtime'=>time(),
              );
             if(UserLogs::create($data)){
                 return true;
             }
         }
         return false;
     }
}
